/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.inteligencia.stage.dataaccess.domain.hibernate;

//import com.inteligencia.stage.business.dto.Entrega.EntregaDTO;
import com.inteligencia.stage.business.dto.LoginDTO;
import com.inteligencia.stage.business.dto.PersonaDTO;
import com.inteligencia.stage.dataaccess.base.hibernate.HibernateGenericDAO;
import com.inteligencia.stage.dataaccess.domain.PersonaDAO;
import com.inteligencia.stage.dataaccess.model.TpersonaVO;
import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author igorov
 */
public class HibernatePersonaDAO extends HibernateGenericDAO<TpersonaVO, Integer> implements PersonaDAO {

    public HibernatePersonaDAO() {
        super(TpersonaVO.class);
    }

    @Override
    public TpersonaVO getByLogin(LoginDTO loginDTO) {
//        List<TpersonaVO> personas = executeSQLQuery("SELECT * FROM tpersona WHERE cemail='" + loginDTO.getUser() + "' AND cpassword='" + loginDTO.getPass() + "';");
        DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TpersonaVO.class);
        detachedCriteria.add(Restrictions.eq("cemail", loginDTO.getUser().trim())).
                add(Restrictions.eq("cpassword", loginDTO.getPass().trim()));
        List<TpersonaVO> personas = listByCriteria(detachedCriteria);
        if (personas.size() > 0) {
            return personas.get(0);
        }
        return null;
    }

    @Override
    public void save(PersonaDTO persona) {
        TpersonaVO personaVO = persona.toVO();
        try {
            saveOrUpdate(personaVO);
        } catch (Exception e) {
            System.out.println("e: " + e.getMessage());
        }

    }
//    @Override
//    public List<EntregaDTO> getList(int nCodEve) {
//                return this.getSession().
//                createSQLQuery("SELECT a.nCodPer, a.cNomPer, a.cApePat, a.cApeMat, b.cTipIns "+
//                "FROM tpersona AS a "+
//                "INNER JOIN tinscripcion AS b ON a.nCodPer = b.nCodPer "+
//                "INNER JOIN tevento AS c ON b.nCodEve = c.nCodEve "+
//                "WHERE c.nCodEve="+nCodEve+";").
//                addEntity(EntregaDTO.class).list();
//
//    }
}
